home *** CD-ROM | disk | FTP | other *** search
/ LiquidLibrary 2005 February / LiquidLibrary 2005 February - Disc 1.iso / pc / Portfolio Browser / Filters / PDF / LIB / gs_dpnxt.ps < prev    next >
Text File  |  2003-01-03  |  4KB  |  103 lines

  1. %    Copyright (C) 1997, 1998 Aladdin Enterprises.  All rights reserved.
  2. % This software is licensed to a single customer by Artifex Software Inc.
  3. % under the terms of a specific OEM agreement.
  4.  
  5. % $RCSfile$ $Revision$
  6. % gs_dpnxt.ps
  7. % NeXT Display PostScript extensions
  8.  
  9. % Define the operation values for compositing.  These must match the values
  10. % in gsdpnext.h, which also are the ones from the NeXT documentation.
  11. % We put them in systemdict, which seems like as good a place as any.
  12. mark
  13.   /Clear /Copy /Sover /Sin /Sout /Satop /Dover /Din /Dout /Datop /Xor
  14.   /PlusD /PlusL /Highlight    % not sure about Highlight
  15. counttomark { counttomark 1 sub def } repeat pop
  16.  
  17. % We implement readimage and sizeimage using the following 3 otherwise
  18. % undocumented lower-level operators:
  19. %
  20. %    <x> <y> <width> <height> <matrix> .sizeimagebox
  21. %      <dev_x> <dev_y> <dev_width> <dev_height> <matrix>
  22. %
  23. %    - .sizeimageparams <bits/sample> <multiproc> <ncolors>
  24. %
  25. %    <device> <x> <y> <width> <max_height> <alpha?> <std_depth|null>
  26. %      <string> .getbitsrect <height> <substring>
  27. %
  28. % NOTE: These operators are subject to change without notice!
  29.  
  30. % Implement readimage using .getbitsrect.  Experimentation on a NeXT system
  31. % shows that the data is always returned in order of increasing device Y,
  32. % regardless of the CTM.
  33. %
  34. % Note that we can't make stack protection work for this operator,
  35. % because it must remove its operands from the stack before calling
  36. % the supplied procedure(s).
  37.  
  38. /readimage {        % <x> <y> <width> <height> <proc> [... <procN-1>]
  39.             %   <string> <alpha?> readimage -
  40.   .sizeimageparams exch {
  41.     % multiproc = true.  If N > 1, store the procedures in an array.
  42.     exch pop 1 index { 1 add } if
  43.     % Stack: ... string alpha? nprocs
  44.     dup 1 eq {
  45.       pop false        % only 1 procedure, multiproc is irrelevant
  46.     } {
  47.       dup array 4 1 roll 3 add 2 roll astore 3 1 roll true
  48.     } ifelse
  49.   } {
  50.     % multiproc = false.
  51.     pop pop false
  52.   } ifelse
  53.     % Map the rectangle to device coordinates.
  54.     % Stack: x y w h proc(s) str alpha? multi?
  55.   8 -4 roll matrix .sizeimagebox pop 8 4 roll
  56.     % Make sure we allocate the operand array in local VM
  57.     % to avoid a possible invalidaccess.
  58.   .currentglobal false .setglobal 9 1 roll
  59.   exch { 1 } { 0 } ifelse exch        % alpha is last, if present
  60.   exch 4 1 roll 8 array astore exch .setglobal
  61.   {    % Read out a block of scan lines and pass them to the procedure.
  62.     % Stack: [x y w h alpha? proc(s) str multi?] -- we must consume this.
  63.     dup 3 get 0 eq { pop exit } if
  64.     aload 9 1 roll pop exch pop currentdevice 7 1 roll
  65.     % Always read out the data as standard (not native) pixels.
  66.     .sizeimageparams pop pop exch .getbitsrect
  67.     % Stack: [x y w h alpha? proc(s) str multi?] hread substr
  68.     3 -1 roll
  69.     % Stack: hread substr [x y w h alpha? proc(s) str multi?]
  70.     dup 1 2 copy get 5 index add put
  71.     % Stack: hread substr [x y' w h alpha? proc(s) str multi?]
  72.     dup 3 2 copy get 6 -1 roll sub put
  73.     % Stack: substr [x y' w h' alpha? proc(s) str multi?]
  74.     dup 5 get exch 7 get {
  75.     % multiproc = true, pass each plane to a different procedure.
  76.     % Stack: substr procs
  77.       0 1 2 index length 1 sub {
  78.     % Push 1 plane and its procedure under the top 2 elements.
  79.     % Stack: ... substr procs plane#
  80.     2 index length 2 index length idiv    % bytes per plane
  81.     dup 2 index mul exch
  82.     % Stack: ... substr procs plane# start length
  83.     4 index 3 1 roll getinterval 4 1 roll
  84.     2 copy get 4 1 roll pop
  85.       } for
  86.       exch pop length 2 mul .execn
  87.     } {
  88.     % multiproc = false, just call the procedure.
  89.       exec
  90.     } ifelse
  91.   } //systemdict /exec get 3 packedarray cvx loop
  92. } bind odef
  93.  
  94. % Implement sizeimage using lower-level operators.
  95.  
  96. /sizeimage {        % <x> <y> <width> <height> <matrix> sizeimage
  97.             %   <devwidth> <devheight> <bits/sample> <matrix>
  98.             %   <multiproc> <ncolors>
  99.   .sizeimagebox 5 -2 roll pop pop
  100.   .sizeimageparams 3 -1 roll 4 1 roll
  101. } bind odef
  102.